package com.htthorizon.common.datasource.handler;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Properties;

/**
 * @author Brilliant
 */

@Intercepts(
        @Signature(type= Executor.class,method = "update",args = {MappedStatement.class, Object.class})
)
@Component
public class InsertOrUpdateHandler implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        //被代理对象
        Object target = invocation.getTarget();

        //代理方法
        Method method = invocation.getMethod();

        //方法参数
        Object[] args = invocation.getArgs();





        // do something ...方法拦截前执行代码块



        // 本方法执行（这就是执行被拦截的源方法）
        Object result = invocation.proceed();


        // do something ...方法拦截后执行代码块

        return result;

    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        System.out.println("Properties"+properties);
    }
}
